package vn.orderonline.core.commons.utils;

import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ObjectWriter;


public class StringUtils extends org.springframework.util.StringUtils {

	public static final String EMPTY = "";
	public static final String NULL = "null";

	public static boolean isNullOrEmpty(String string) {
		if (string == null || string.equalsIgnoreCase(NULL)
				|| string.equals(EMPTY)) {
			return true;
		}
		return false;
	}
	
	public static String parseToJSON(Object obj) {
		ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
		String strJson = null;
		try {
			strJson = ow.writeValueAsString(obj);
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return strJson;
	}
	
	public static void main(String[] args) {
		System.out.println(parseToJSON(null));
	}

}
